<!DOCTYPE html>
<html lang="zh-Hans">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 6.0.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"malossov.top","root":"/","scheme":"Pisces","version":"7.8.0","exturl":false,"sidebar":{"position":"right","display":"always","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="基础命令和服务部分 背景故事：呜呼哀哉，我因为没有趁着第一波危机从学校逃跑，不幸地阳了，没有精力完成实验报告和拷贝文件，只好在家远程连接到学校的电脑上完成作业，他需要做一些操作让他的台机能在家中被连接。   我已有的知识：  Linux基础服务命令：systemctl,crontab…… 网页搜索能力   我已有的设备：  台式电脑：在宿舍，运行Windows11和Ubuntu22.04.1 香橙">
<meta property="og:type" content="article">
<meta property="og:title" content="如何在宿舍有幽灵电脑">
<meta property="og:url" content="https://malossov.top/2022/12/28/ProgramLearn/UbuntuUsage/Linux%E5%9F%BA%E7%A1%80%E5%AE%9E%E8%B7%B5/index.html">
<meta property="og:site_name" content="MAL&#39;S_BLOG">
<meta property="og:description" content="基础命令和服务部分 背景故事：呜呼哀哉，我因为没有趁着第一波危机从学校逃跑，不幸地阳了，没有精力完成实验报告和拷贝文件，只好在家远程连接到学校的电脑上完成作业，他需要做一些操作让他的台机能在家中被连接。   我已有的知识：  Linux基础服务命令：systemctl,crontab…… 网页搜索能力   我已有的设备：  台式电脑：在宿舍，运行Windows11和Ubuntu22.04.1 香橙">
<meta property="og:locale">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218132940999.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218133130102.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218133246914.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218133346827.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218133620133.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218134507120.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/08090352-4e0aa3fe4f404b3491df384758229be1.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218135121983.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218135244996.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218135419224.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218135844577.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218140530400.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218141250231.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218141622686.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218141901735.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218142149380.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218141710251.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218123143305.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218122929405.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/image-20221218132505568.png">
<meta property="og:image" content="http://picgo.malossov.top/malpicbed/IMG_20221218_142310.jpg">
<meta property="article:published_time" content="2022-12-28T06:00:53.000Z">
<meta property="article:modified_time" content="2023-01-12T02:52:37.187Z">
<meta property="article:author" content="MALossov">
<meta property="article:tag" content="Linux">
<meta property="article:tag" content="Ubuntu">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://picgo.malossov.top/malpicbed/image-20221218132940999.png">

<link rel="canonical" href="https://malossov.top/2022/12/28/ProgramLearn/UbuntuUsage/Linux%E5%9F%BA%E7%A1%80%E5%AE%9E%E8%B7%B5/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-Hans'
  };
</script>

  <title>如何在宿舍有幽灵电脑 | MAL'S_BLOG</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">MAL'S_BLOG</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Welcome to Malossov's Personal Archieve!</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-主页">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>主页</a>

  </li>
        <li class="menu-item menu-item-标签">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-分类">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-归档">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-友链">

    <a href="/links/" rel="section"><i class="fa fa-link fa-fw"></i>友链</a>

  </li>

    <li> <a title="把这个链接拖到你的Chrome收藏夹工具栏中" href='javascript:(function() {
    function c() {
        var e = document.createElement("link");
        e.setAttribute("type", "text/css");
        e.setAttribute("rel", "stylesheet");
        e.setAttribute("href", f);
        e.setAttribute("class", l);
        document.body.appendChild(e)
    }

    function h() {
        var e = document.getElementsByClassName(l);
        for (var t = 0; t < e.length; t++) {
            document.body.removeChild(e[t])
        }
    }

    function p() {
        var e = document.createElement("div");
        e.setAttribute("class", a);
        document.body.appendChild(e);
        setTimeout(function() {
            document.body.removeChild(e)
        }, 100)
    }

    function d(e) {
        return {
            height : e.offsetHeight,
            width : e.offsetWidth
        }
    }

    function v(i) {
        var s = d(i);
        return s.height > e && s.height < n && s.width > t && s.width < r
    }

    function m(e) {
        var t = e;
        var n = 0;
        while (!!t) {
            n += t.offsetTop;
            t = t.offsetParent
        }
        return n
    }

    function g() {
        var e = document.documentElement;
        if (!!window.innerWidth) {
            return window.innerHeight
        } else if (e && !isNaN(e.clientHeight)) {
            return e.clientHeight
        }
        return 0
    }

    function y() {
        if (window.pageYOffset) {
            return window.pageYOffset
        }
        return Math.max(document.documentElement.scrollTop, document.body.scrollTop)
    }

    function E(e) {
        var t = m(e);
        return t >= w && t <= b + w
    }

    function S() {
        var e = document.createElement("audio");
        e.setAttribute("class", l);
        e.src = i;
        e.loop = false;
        e.addEventListener("canplay", function() {
            setTimeout(function() {
                x(k)
            }, 500);
            setTimeout(function() {
                N();
                p();
                for (var e = 0; e < O.length; e++) {
                    T(O[e])
                }
            }, 15500)
        }, true);
        e.addEventListener("ended", function() {
            N();
            h()
        }, true);
        e.innerHTML = " <p>If you are reading this, it is because your browser does not support the audio element. We recommend that you get a new browser.</p> <p>";
        document.body.appendChild(e);
        e.play()
    }

    function x(e) {
        e.className += " " + s + " " + o
    }

    function T(e) {
        e.className += " " + s + " " + u[Math.floor(Math.random() * u.length)]
    }

    function N() {
        var e = document.getElementsByClassName(s);
        var t = new RegExp("\\b" + s + "\\b");
        for (var n = 0; n < e.length; ) {
            e[n].className = e[n].className.replace(t, "")
        }
    }

    var e = 30;
    var t = 30;
    var n = 350;
    var r = 350;
    var i = "//7xuupy.com1.z0.glb.clouddn.com/tongxingSibel%20-%20Im%20Sorry.mp3";
    var s = "mw-harlem_shake_me";
    var o = "im_first";
    var u = ["im_drunk", "im_baked", "im_trippin", "im_blown"];
    var a = "mw-strobe_light";
    var f = "//s3.amazonaws.com/moovweb-marketing/playground/harlem-shake-style.css";
    var l = "mw_added_css";
    var b = g();
    var w = y();
    var C = document.getElementsByTagName("*");
    var k = null;
    for (var L = 0; L < C.length; L++) {
        var A = C[L];
        if (v(A)) {
            if (E(A)) {
                k = A;
                break
            }
        }
    }
    if (A === null) {
        console.warn("Could not find a node of the right size. Please try a different page.");
        return
    }
    c();
    S();
    var O = [];
    for (var L = 0; L < C.length; L++) {
        var A = C[L];
        if (v(A)) {
            O.push(A)
        }
    }
    })()    '>High一下</a> </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-Hans">
    <link itemprop="mainEntityOfPage" href="https://malossov.top/2022/12/28/ProgramLearn/UbuntuUsage/Linux%E5%9F%BA%E7%A1%80%E5%AE%9E%E8%B7%B5/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/uploads/avator.png">
      <meta itemprop="name" content="MALossov">
      <meta itemprop="description" content="是很菜的人的很菜的博客捏，无栈工程学徒ing。">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="MAL'S_BLOG">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          如何在宿舍有幽灵电脑
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2022-12-28 14:00:53" itemprop="dateCreated datePublished" datetime="2022-12-28T14:00:53+08:00">2022-12-28</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2023-01-12 10:52:37" itemprop="dateModified" datetime="2023-01-12T10:52:37+08:00">2023-01-12</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%8E%AF%E5%A2%83/" itemprop="url" rel="index"><span itemprop="name">环境</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="基础命令和服务部分"><a href="#基础命令和服务部分" class="headerlink" title="基础命令和服务部分"></a>基础命令和服务部分</h2><blockquote>
<p>背景故事：呜呼哀哉，我因为没有趁着第一波危机从学校逃跑，不幸地阳了，没有精力完成实验报告和拷贝文件，只好在家远程连接到学校的电脑上完成作业，他需要做一些操作让他的台机能在家中被连接。</p>
</blockquote>
<ul>
<li><p>我已有的知识：</p>
<ul>
<li>Linux基础服务命令：<code>systemctl</code>,<code>crontab</code>……</li>
<li>网页搜索能力</li>
</ul>
</li>
<li><p>我已有的设备：</p>
<ul>
<li>台式电脑：在宿舍，运行Windows11和Ubuntu22.04.1</li>
<li>香橙派3：在宿舍，运行Ubuntu18.04</li>
<li>笔记本：带回宿舍用以连接</li>
</ul>
</li>
<li><p>我需要做的：</p>
<ul>
<li>让香橙派能够唤醒台式电脑</li>
<li>保持宿舍需要每时每刻发包的电信网络不断网</li>
<li>让这两台设备能够被远控</li>
</ul>
</li>
<li><p>解决方案：</p>
<ul>
<li>唤醒问题：使用魔术封包的方法让主机支持WakeOnLan</li>
<li>联网问题：使用crontab定时任务，让香橙派每一分钟给路由器发包，保证联网保活的包不断</li>
<li>远程连接问题：使用内网透传工具</li>
</ul>
</li>
</ul>
<h2 id="服务构建"><a href="#服务构建" class="headerlink" title="服务构建"></a>服务构建</h2><h3 id="保活：Crontab定时命令服务"><a href="#保活：Crontab定时命令服务" class="headerlink" title="保活：Crontab定时命令服务"></a>保活：Crontab定时命令服务</h3><h4 id="数据包流量分析"><a href="#数据包流量分析" class="headerlink" title="数据包流量分析"></a>数据包流量分析</h4><blockquote>
<p>背景故事：由于电信网络糟糕的设计，每次重启路由器时（即断电后第二天），都需要重新重新验证，所以必须进行保活处理。</p>
</blockquote>
<ol>
<li><p>首先验证网络登录方式，使用BurpSuite对登录网络进行抓包：（由于现在是远程访问，就改包越权访问到主页演示一下orz，一旦登出我两台设备都没网了害得等服务主动发包帮我续上）<img src="http://picgo.malossov.top/malpicbed/image-20221218132940999.png" alt="image-20221218132940999"></p>
<ol>
<li>最终抓到的包为：<img src="http://picgo.malossov.top/malpicbed/image-20221218133130102.png" alt="image-20221218133130102"></li>
</ol>
</li>
<li><p>稍稍修改为curl命令的语法并写成可以直接运行的脚本形式:<img src="http://picgo.malossov.top/malpicbed/image-20221218133246914.png" alt="image-20221218133246914"></p>
<blockquote>
<p>curl命令语法：<a target="_blank" rel="noopener" href="https://blog.csdn.net/u013514928/article/details/102810250">curl命令用法_追梦菜鸟的博客-CSDN博客_curl语法</a></p>
<p>基础语法为：curl [options…] <url>，主要有：</url></p>
<ol>
<li>-H/—header   LINE     (H) <em># 添加请求头, 可添加多个 -H 参数,参数格式: -H “NAME: VALUE”</em></li>
<li>-o/—output FILE   FILE     <em># 把响应内容输出到指定文件</em></li>
<li>-F/—form    CONTENT (H)  # <em>参考格式: -F “name1=@/filepath” -F “name2=stringvalue”</em></li>
<li>-b/—cookie   STRING/FILE (H) <em># 请求头的 Cookie 字段, 以字符串的形式提供,**或从指定 cookie 文件中读取</em></li>
<li>-d/—data    DATA   (H)</li>
</ol>
</blockquote>
</li>
<li><p>这时候可以使用终端运行脚本进行验证：<img src="http://picgo.malossov.top/malpicbed/image-20221218133346827.png" alt="image-20221218133346827"></p>
</li>
<li><p>下面把脚本使用scp命令拷贝给香橙派之后进行定时任务的书写：<img src="http://picgo.malossov.top/malpicbed/image-20221218133620133.png" alt="image-20221218133620133"></p>
<blockquote>
<p>SCP命令用法为：<a target="_blank" rel="noopener" href="https://www.runoob.com/linux/linux-comm-scp.html">Linux scp命令 | 菜鸟教程 (runoob.com)</a></p>
<ol>
<li>本地到远程：scp local_file remote_username@remote_ip:remote_file </li>
<li>远程到本地：scp root@www.runoob.com:/home/root/others/music /home/space/music/1.mp3 </li>
</ol>
</blockquote>
</li>
</ol>
<h4 id="Crontab保活"><a href="#Crontab保活" class="headerlink" title="Crontab保活"></a>Crontab保活</h4><blockquote>
<p>网上一般的都是比较老的<code>/etc/cron</code>和直接开启crond服务，但是ubuntu升级到systemctl下的系统步骤较少，这里随便试一下成功了。</p>
</blockquote>
<ol>
<li><p>我这里ubuntu自带了crontab的命令。<img src="http://picgo.malossov.top/malpicbed/image-20221218134507120.png" alt="image-20221218134507120"></p>
</li>
<li><p>调用cron -e选择vim进行服务文件的编辑。cron的格式为：<img src="http://picgo.malossov.top/malpicbed/08090352-4e0aa3fe4f404b3491df384758229be1.png" alt="《crontab命令详解 含启动/重启/停止》"></p>
<blockquote>
<p>在以上各个字段中，还可以使用以下特殊字符：</p>
<ul>
<li><p>星号（*）：代表所有可能的值，例如month字段如果是星号，则表示在满足其它字段的制约条件后每月都执行该命令操作。</p>
</li>
<li><p>逗号（,）：可以用逗号隔开的值指定一个列表范围，例如，“1,2,5,7,8,9”</p>
</li>
<li><p>中杠（-）：可以用整数之间的中杠表示一个整数范围，例如“2-6”表示“2,3,4,5,6”</p>
</li>
<li><p>正斜线（/）：可以用正斜线指定时间的间隔频率，例如“0-23/2”表示每两小时执行一次。同时正斜线可以和星号一起使用，例如*/10，如果用在minute字段，表示每十分钟执行一次。</p>
</li>
</ul>
</blockquote>
</li>
<li><p><code>crontab -l</code>列出cron服务内容：在每分钟执行一次curl的操作，同时在每小时删除一次日志文件。cron当中必须使用绝对路径，否则会运行失败。<img src="http://picgo.malossov.top/malpicbed/image-20221218135121983.png" alt="image-20221218135121983"></p>
<ol>
<li>network.sh内容：将内容存入tmp.txt日志当中。<img src="http://picgo.malossov.top/malpicbed/image-20221218135244996.png" alt="image-20221218135244996"></li>
</ol>
</li>
<li><p>接下来使能服务，注意ubuntu中cron的服务不是<code>crond</code>，而是<code>cron.service</code><img src="http://picgo.malossov.top/malpicbed/image-20221218135419224.png" alt="image-20221218135419224"></p>
<blockquote>
<p>systemctl基本的服务操作：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">systemctl start   &lt;docker&gt;.service    //启动</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">systemctl restart &lt;docker&gt;.service    //重启</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">systemctl stop    &lt;docker&gt;.service    //停止</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">systemctl reload  &lt;docker&gt;.service    //重新加载</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">systemctl <span class="built_in">enable</span>  &lt;docker&gt;.service    //加入开机启动</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">systemctl <span class="built_in">disable</span> &lt;docker&gt;.service    //取消开机启动</span></span><br></pre></td></tr></table></figure>
<p>systemctl配置详解：</p>
<p><a target="_blank" rel="noopener" href="https://juejin.cn/post/6963550409482829832">详细讲解systemctl（附常用指令） - 掘金 (juejin.cn)</a></p>
</blockquote>
</li>
<li><p>可以观察tmp.txt日志文件看看是不是真的curl了，也可以使用<code>systemctl status &lt;service&gt;</code>进行日志查看：<img src="http://picgo.malossov.top/malpicbed/image-20221218135844577.png" alt="image-20221218135844577"></p>
</li>
<li><p>可以看到已经成功了。</p>
</li>
</ol>
<h3 id="远程登录开启"><a href="#远程登录开启" class="headerlink" title="远程登录开启"></a>远程登录开启</h3><blockquote>
<p>由于我的路由器时电信送的便宜玩意，管理后台特别烂，所以只有DHCP的局域网IP分配，非常伤心。无法配置todesk的远程唤醒，只能使用ubuntu下的ethtools工具进行相关配置。</p>
<p><strong>所以我大概是简体中文ubuntu22唤醒第一人了？</strong></p>
</blockquote>
<p>国内互联网上的资料非常老，在服务管理这一块用的还是古老的<code>rc.local</code>方式，而这种方式在ubuntu22当中根本就没有被使能，所以必须还是使用systemd的方式进行服务的追加和保活。</p>
<h4 id="被唤醒主机"><a href="#被唤醒主机" class="headerlink" title="被唤醒主机"></a>被唤醒主机</h4><ol>
<li><p>安装<code>ethtool</code>软件包：<code>sudo apt install ethtool -y</code></p>
</li>
<li><p>更改并查看网卡状态，将网卡的在线唤醒模式开启：<code>sudo ethtool -s enp5s0 wol g</code></p>
<ol>
<li>使用<code>ethtool enp5s0</code>查看网卡状态，<strong>Wake-on:</strong>这一项为<strong>g</strong>表示已经开启了唤醒：<img src="http://picgo.malossov.top/malpicbed/image-20221218140530400.png" alt="image-20221218140530400"></li>
</ol>
</li>
<li><p>但是由于Linux万物皆文件的特性，在重启时，网卡的配置文件会被覆盖，因此采用systemd的方式，编写系统服务完成自动唤醒网卡的操作：</p>
<ol>
<li><p>使用<code>--preserve-env</code>操作进行提权，直接编写systemctl服务：<code>sudo --preserve-env systemctl edit --force --full wol-enable.service</code></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[Unit]    # 服务本身的名字和说明</span><br><span class="line">Description=Enable Wake-up on LAN</span><br><span class="line"></span><br><span class="line">[Service]</span><br><span class="line">Type=oneshot    # 只执行一项任务、随后立即退出的服务</span><br><span class="line">ExecStart=/sbin/ethtool -s enp2s0   wol g    # 执行的命令，注意ethtool的位置是在sbin下的，泪目</span><br><span class="line"></span><br><span class="line">[Install]</span><br><span class="line">WantedBy=basic.target    # 挂载在basic.target下，优先级必须比我用户启动高</span><br></pre></td></tr></table></figure>
</li>
<li><p>详细配置2.0：<a target="_blank" rel="noopener" href="https://www.cnblogs.com/zwcry/p/9602756.html">linux systemctl 指令 —— 阮一峰 - 七脉 - 博客园 (cnblogs.com)</a></p>
</li>
</ol>
</li>
</ol>
<h4 id="唤醒机器"><a href="#唤醒机器" class="headerlink" title="唤醒机器"></a>唤醒机器</h4><ol>
<li><p>查询到被唤醒机器的mac地址之后，使用魔术封包即可唤醒，也是安装个<code>wakeonlan</code>软件包就行。<img src="http://picgo.malossov.top/malpicbed/image-20221218141250231.png" alt="image-20221218141250231"></p>
</li>
<li><p>可以看到ubuntu的软件包是全局发送的，不像windows下某些解决方案必须固定ip。</p>
<ol>
<li>个人学了基本sdn控制器之后的理解大概是路由会记住主机的mac表然后发送给对应主机。</li>
</ol>
</li>
<li><p>为了配合简洁使用写了个flask服务：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@app.route(<span class="params"><span class="string">&#x27;/&#x27;</span>, methods=[<span class="string">&#x27;GET&#x27;</span>]</span>)</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">hello_world</span>():</span><br><span class="line">    <span class="keyword">return</span> <span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">    &lt;form action=&quot;/&quot; method=&quot;post&quot;&gt;</span></span><br><span class="line"><span class="string">        &lt;input type=&quot;submit&quot; value=&quot;SendRemoteRebootMessage&quot;&gt;</span></span><br><span class="line"><span class="string">    &lt;/form&gt;</span></span><br><span class="line"><span class="string">    &#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="meta">@app.route(<span class="params"><span class="string">&#x27;/&#x27;</span>, methods=[<span class="string">&#x27;POST&#x27;</span>]</span>)</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">post</span>():</span><br><span class="line">    <span class="keyword">import</span> subprocess</span><br><span class="line">    subprocess.call(<span class="string">&#x27;./a.sh&#x27;</span>)</span><br><span class="line">    <span class="keyword">return</span> <span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">    Successfully Reboot from remote</span></span><br><span class="line"><span class="string">    &lt;form action=&quot;/&quot; method=&quot;post&quot;&gt;</span></span><br><span class="line"><span class="string">        &lt;input type=&quot;submit&quot; value=&quot;Resend Message&quot;&gt;</span></span><br><span class="line"><span class="string">    &lt;/form&gt;</span></span><br><span class="line"><span class="string">    &#x27;&#x27;&#x27;</span></span><br></pre></td></tr></table></figure>
<ol>
<li>对应服务程序：由于flask这个pip包的原因，不能使用<code>nohup</code>和<code>&amp;</code>在后台运行，所以状态一直是loaded，但是日志是没有问题的。<img src="http://picgo.malossov.top/malpicbed/image-20221218141622686.png" alt="image-20221218141622686"></li>
<li>来点cpolar透传5000端口之后的样子：<img src="http://picgo.malossov.top/malpicbed/image-20221218141901735.png" alt="image-20221218141901735"></li>
</ol>
</li>
</ol>
<h3 id="外网透传和远控"><a href="#外网透传和远控" class="headerlink" title="外网透传和远控"></a>外网透传和远控</h3><ol>
<li>透传使用的是cpolar白嫖的三个通道，配置方法在文档里面很详细：<a target="_blank" rel="noopener" href="https://www.cpolar.com/docs，还有`9200端口`的webui，基本上很无脑：![image-20221218142023423](http://picgo.malossov.top/malpicbed/image-20221218142023423.png">https://www.cpolar.com/docs，还有`9200端口`的webui，基本上很无脑：![image-20221218142023423](http://picgo.malossov.top/malpicbed/image-20221218142023423.png</a>)</li>
<li>控制方面使用的是<code>toDesk</code>，非常流畅，也是对Linux支持较为友好。<img src="http://picgo.malossov.top/malpicbed/image-20221218142149380.png" alt="image-20221218142149380"></li>
</ol>
<h2 id="后续使用"><a href="#后续使用" class="headerlink" title="后续使用"></a>后续使用</h2><h3 id="双系统切换"><a href="#双系统切换" class="headerlink" title="双系统切换"></a>双系统切换</h3><p>电脑的默认引导加载程序和管理器因为安装了Ubuntu的缘故被设置成grub2，因此其实对于引导的修改就是对于grub2启动项的修改。</p>
<p><a target="_blank" rel="noopener" href="https://help.ubuntu.com/community/Grub2">Grub2在UbuntuWiki上的介绍</a>：↓简单的部分中文翻译和理解：这里为软件包相关配置，不涉及到<code>grub控制台</code>的配置</p>
<blockquote>
<ol>
<li><p><strong>Grub2介绍：</strong> 是引导加载和管理工具，在进入的时候会提供界面等待用户选择，或者将控制交给系统内核(可以是任意被识别到的系统内核)。</p>
</li>
<li><p><strong>文件结构：</strong></p>
<ol>
<li><code>/etc/grub.d</code>（文件夹）：Grub2脚本</li>
<li><code>/boot/grub</code> （文件夹）：Grub2模块和菜单文件（<code>grub.cfg</code>）</li>
<li><code>/etc/default/grub</code> ：（配置文件）用户主要修改通过这个文件<ol>
<li>应用配置更改：修改<code>grub.d</code>和<code>/etc/default/grub</code>后，运行<code>update-grub</code>，来修改<code>/boot/grub</code>当中的内容。</li>
</ol>
</li>
</ol>
</li>
</ol>
</blockquote>
<h4 id="Linux切换到Windows"><a href="#Linux切换到Windows" class="headerlink" title="Linux切换到Windows"></a>Linux切换到Windows</h4><p>修改grub配置文件，并且运行<code>sudo update-grub</code>即可。</p>
<p><img src="http://picgo.malossov.top/malpicbed/image-20221218141710251.png" alt="image-20221218141710251"></p>
<h4 id="Windows下切换回Linux系统"><a href="#Windows下切换回Linux系统" class="headerlink" title="Windows下切换回Linux系统"></a>Windows下切换回Linux系统</h4><ol>
<li>让Windows正确识别到Linux的文件系统并且能进行修改<ol>
<li>在网上陆续找了一些能识别ext4文件系统的软件但是都效果不佳，最终找到<a target="_blank" rel="noopener" href="https://www.paragon-software.com/home/linuxfs-windows/">Linux File Systems for Windows | Paragon Software (paragon-software.com)</a>可以将Linux盘挂在到Windows系统文件管理器当中<img src="http://picgo.malossov.top/malpicbed/image-20221218123143305.png" alt="image-20221218123143305"></li>
</ol>
</li>
<li>从<code>grub</code>的描述当中可知，<code>grub</code>在进行启动引导时，使用的是<code>/boot/grub</code>当中的模块和菜单文件。直接修改<code>/boot/grub/grub.cfg</code>菜单文件，将默认启动选项移到<code>windows11</code>对应的启动菜单栏目即可。<img src="http://picgo.malossov.top/malpicbed/image-20221218122929405.png" alt="image-20221218122929405"></li>
</ol>
<h3 id="意外失去连接之后怎么办"><a href="#意外失去连接之后怎么办" class="headerlink" title="意外失去连接之后怎么办"></a>意外失去连接之后怎么办</h3><ol>
<li><p>此时局域网还是连通的，使用nmap扫描当前网段的内容。</p>
</li>
<li><p>使用cpolar远程登录到香橙派中。</p>
</li>
<li><p>使用命令：<code>nmap 192.168.101.1-10</code> 扫描10个ip,一般情况下dhcp会将PC分配在1-10当中。因为我都开启了ssh服务，可以通过香橙派作为中继连接主机的ssh服务<img src="http://picgo.malossov.top/malpicbed/image-20221218132505568.png" alt="image-20221218132505568"></p>
</li>
<li><p>此时pc被分配在192.168.101.6上。ssh连接之后重启服务或者重启。</p>
</li>
<li><p>扫描时可以添加如下选项：</p>
<ol>
<li><blockquote>
<p>Windows如果无法扫描到，添加：<code>-Pn</code> 禁止ping访问确定主机是否存在，强力联通；</p>
<p>扫描速度太慢，给予<strong>sudo</strong>权限之后添加<code>-sS</code>进行扫描，更改连接方式，不需要经过TCP三次握手；</p>
<p>或者选择经过TCP三次握手但是修改timeout超时时间，如：<code>--host-timeout 10</code></p>
</blockquote>
</li>
</ol>
</li>
</ol>
<h2 id="关于为什么咕咕了那么久就上传了这个"><a href="#关于为什么咕咕了那么久就上传了这个" class="headerlink" title="关于为什么咕咕了那么久就上传了这个"></a>关于为什么咕咕了那么久就上传了这个</h2><p>因为实在是太纯阳了。</p>
<p><img src="http://picgo.malossov.top/malpicbed/IMG_20221218_142310.jpg" alt="IMG_20221218_142310"></p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Linux/" rel="tag"># Linux</a>
              <a href="/tags/Ubuntu/" rel="tag"># Ubuntu</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2022/09/18/ProgramLearn/1st_GroupMeet/1st-commended/" rel="prev" title="科协软件：STM32简介">
      <i class="fa fa-chevron-left"></i> 科协软件：STM32简介
    </a></div>
      <div class="post-nav-item">
    <a href="/2023/07/29/ProgramLearn/TI/c2000-learn-1/" rel="next" title="TI实时MCU学习-以TILaunchPad为例">
      TI实时MCU学习-以TILaunchPad为例 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4%E5%92%8C%E6%9C%8D%E5%8A%A1%E9%83%A8%E5%88%86"><span class="nav-number">1.</span> <span class="nav-text">基础命令和服务部分</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9C%8D%E5%8A%A1%E6%9E%84%E5%BB%BA"><span class="nav-number">2.</span> <span class="nav-text">服务构建</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BF%9D%E6%B4%BB%EF%BC%9ACrontab%E5%AE%9A%E6%97%B6%E5%91%BD%E4%BB%A4%E6%9C%8D%E5%8A%A1"><span class="nav-number">2.1.</span> <span class="nav-text">保活：Crontab定时命令服务</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%95%B0%E6%8D%AE%E5%8C%85%E6%B5%81%E9%87%8F%E5%88%86%E6%9E%90"><span class="nav-number">2.1.1.</span> <span class="nav-text">数据包流量分析</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Crontab%E4%BF%9D%E6%B4%BB"><span class="nav-number">2.1.2.</span> <span class="nav-text">Crontab保活</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%BF%9C%E7%A8%8B%E7%99%BB%E5%BD%95%E5%BC%80%E5%90%AF"><span class="nav-number">2.2.</span> <span class="nav-text">远程登录开启</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%A2%AB%E5%94%A4%E9%86%92%E4%B8%BB%E6%9C%BA"><span class="nav-number">2.2.1.</span> <span class="nav-text">被唤醒主机</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%94%A4%E9%86%92%E6%9C%BA%E5%99%A8"><span class="nav-number">2.2.2.</span> <span class="nav-text">唤醒机器</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%A4%96%E7%BD%91%E9%80%8F%E4%BC%A0%E5%92%8C%E8%BF%9C%E6%8E%A7"><span class="nav-number">2.3.</span> <span class="nav-text">外网透传和远控</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%90%8E%E7%BB%AD%E4%BD%BF%E7%94%A8"><span class="nav-number">3.</span> <span class="nav-text">后续使用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%8F%8C%E7%B3%BB%E7%BB%9F%E5%88%87%E6%8D%A2"><span class="nav-number">3.1.</span> <span class="nav-text">双系统切换</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#Linux%E5%88%87%E6%8D%A2%E5%88%B0Windows"><span class="nav-number">3.1.1.</span> <span class="nav-text">Linux切换到Windows</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Windows%E4%B8%8B%E5%88%87%E6%8D%A2%E5%9B%9ELinux%E7%B3%BB%E7%BB%9F"><span class="nav-number">3.1.2.</span> <span class="nav-text">Windows下切换回Linux系统</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%84%8F%E5%A4%96%E5%A4%B1%E5%8E%BB%E8%BF%9E%E6%8E%A5%E4%B9%8B%E5%90%8E%E6%80%8E%E4%B9%88%E5%8A%9E"><span class="nav-number">3.2.</span> <span class="nav-text">意外失去连接之后怎么办</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%85%B3%E4%BA%8E%E4%B8%BA%E4%BB%80%E4%B9%88%E5%92%95%E5%92%95%E4%BA%86%E9%82%A3%E4%B9%88%E4%B9%85%E5%B0%B1%E4%B8%8A%E4%BC%A0%E4%BA%86%E8%BF%99%E4%B8%AA"><span class="nav-number">4.</span> <span class="nav-text">关于为什么咕咕了那么久就上传了这个</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="MALossov"
      src="/uploads/avator.png">
  <p class="site-author-name" itemprop="name">MALossov</p>
  <div class="site-description" itemprop="description">是很菜的人的很菜的博客捏，无栈工程学徒ing。</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives">
          <span class="site-state-item-count">35</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">categories</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
        <span class="site-state-item-count">29</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/malossov" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;malossov" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://www.zhihu.com/people/yi-wan-nzlao-si-ji" title="知乎 → https:&#x2F;&#x2F;www.zhihu.com&#x2F;people&#x2F;yi-wan-nzlao-si-ji" rel="noopener" target="_blank"><i class="fab fa-zhihu fa-fw"></i>知乎</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://gitee.com/malossov" title="Gitee → https:&#x2F;&#x2F;gitee.com&#x2F;malossov" rel="noopener" target="_blank"><i class="fab fa-gitee fa-fw"></i>Gitee</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        
  <div class="beian"><a href="https://beian.miit.gov.cn/" rel="noopener" target="_blank">蜀ICP备2023019138号 </a>
  </div>

<div class="copyright">
  
  &copy; 2022 – 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">MALossov</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a>
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>


  <script defer src="/lib/three/three.min.js"></script>
    <script defer src="/lib/three/three-waves.min.js"></script>


  













<script>
if (document.querySelectorAll('pre.mermaid').length) {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js', () => {
    mermaid.initialize({
      theme    : 'forest',
      logLevel : 3,
      flowchart: { curve     : 'linear' },
      gantt    : { axisFormat: '%m/%d/%Y' },
      sequence : { actorMargin: 50 }
    });
  }, window.mermaid);
}
</script>


  

  

  


<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/love.js"></script>
<!-- 背景动画 -->
<script type="text/javascript" src="/js/src/particle.js"></script>


</body>
</html>
